package com.gxa.meiye.admin.service.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gxa.meiye.admin.mapper.ScheduleMapper;
import com.gxa.meiye.admin.service.ScheduleService;
import com.gxa.meiye.admin.thread.UserThreadLocal;
import com.gxa.meiye.core.pojo.domain.IncomeAndExpenditureinfo;
import com.gxa.meiye.core.pojo.domain.ScheduleInfo;
import com.gxa.meiye.core.pojo.vo.TherapistLoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ScheduleServiceImpl implements ScheduleService {
    @Autowired
    private ScheduleMapper scheduleMapper;
    @Override
    public List<ScheduleInfo> getMySchedule() throws JsonProcessingException {
        Object o = UserThreadLocal.get();
        ObjectMapper objectMapper = new ObjectMapper();
        TherapistLoginInfo therapistLoginInfo1 = objectMapper.readValue(o.toString(), TherapistLoginInfo.class);
        //从token中取出美疗师傅id
        Integer id = therapistLoginInfo1.getId();
        System.out.println(id);
        List<ScheduleInfo> mySchedule = scheduleMapper.getMySchedule(id);
        return mySchedule;


    }

    @Override
    public List<IncomeAndExpenditureinfo> getMymoney() throws JsonProcessingException {
        Object o = UserThreadLocal.get();
        ObjectMapper objectMapper = new ObjectMapper();
        TherapistLoginInfo therapistLoginInfo1 = objectMapper.readValue(o.toString(), TherapistLoginInfo.class);
        //从token中取出美疗师傅id
        Integer id1 = therapistLoginInfo1.getId();
        List<IncomeAndExpenditureinfo> mymoney = scheduleMapper.getMymoney(id1);
        return mymoney;
    }

    @Override
    public List<IncomeAndExpenditureinfo> getClearmoney() throws JsonProcessingException {
        Object o = UserThreadLocal.get();
        ObjectMapper objectMapper = new ObjectMapper();
        TherapistLoginInfo therapistLoginInfo1 = objectMapper.readValue(o.toString(), TherapistLoginInfo.class);
        //从token中取出美疗师傅id
        Integer id2 = therapistLoginInfo1.getId();
        System.out.println(id2);
        List<IncomeAndExpenditureinfo> clearmoney = scheduleMapper.getClearmoney(id2);
        return clearmoney;
    }


}
